<template>
  <right-template :title="componentData.title" :tabName="componentData.tabName">
    <el-form class="right-menu margin-bottom-10">
      <p class="margin-left-right-16 margin-top-10">菜单栏背景</p>
      <switch-normal v-model="commonAttr.isFixed" label="是否吸顶" @change="onChangeAttr"></switch-normal>
      <slider-normal v-model="commonAttr.fontSize" label="字号" :max="100" :step="1" @change="onChangeAttr"></slider-normal>
      <color-normal v-model="commonAttr.color" label="字体颜色" format="rgb" @change="onChangeAttr"></color-normal>
      <color-normal v-model="commonAttr.selectedColor" label="选中字体颜色" format="rgb" @change="onChangeAttr"></color-normal>
      <color-normal v-model="commonAttr.backgroundColor" label="背景颜色" format="rgb" @change="onChangeAttr"></color-normal>
      <color-normal v-model="commonAttr.seletedBgColor" label="选中背景颜色" format="rgb" @change="onChangeAttr"></color-normal>
      <input-normal label="边距" placeholder="上 右 下 左" v-model="commonAttr.margin" @change="onChangeAttr"></input-normal>
      <input-normal label="内距" placeholder="上 右 下 左" v-model="commonAttr.padding" @change="onChangeAttr"></input-normal>

      <el-divider content-position="center">按钮区设置</el-divider>
      <input-normal label="图片宽度" v-model="commonAttr.width" @change="onChangeAttr"></input-normal>
      <input-normal label="图片高度" v-model="commonAttr.height" @change="onChangeAttr"></input-normal>
      <textarea-normal v-if="lists[0].eventType == 'compVisibleInComps'" label="高度组件参数" placeholder='影响高度组件参数：{"distanceBottom":500,"compId":""}' v-model="commonAttr.heightEffectParams" @change="onChangeAttr"></textarea-normal>
      
      <el-button type="primary" @click.stop="onAddItem" class="margin-left-right-16 margin-bottom-10" icon="Plus">增加按钮区</el-button>
      <input-normal label="默认选中tab索引" v-model="commonAttr.tabIndex" @change="onChangeAttr"></input-normal>
      <el-collapse v-model="activeNames">
        <el-collapse-item v-for="(item, index) in lists" :name="index+1" :key="'drag_'+index" class="list-group-item">
            <template #title>
            按钮区{{index+1}}<i class="jy-icon-delete el-collapse-item__arrow" @click.stop="onDeleteItem(index)"></i>
          </template>
          <p class="margin-left-right-16 margin-top-10">按钮图片</p>
          <add-img-con :url="item.url" picAttr="url" :index="index" :height="100" :isCrop="false" :isDelete="true" class="margin-left-right-16"></add-img-con>
          <p class="margin-left-right-16 margin-top-10">选中按钮图片</p>
          <add-img-con :url="item.selectedBgUrl" picAttr="selectedBgUrl" :index="index" :height="100" :isCrop="false" :isDelete="true" class="margin-left-right-16"></add-img-con>
          <div v-if="!item.url">
            <input-normal class="margin-top-10" :placeholder="item.icon" label="菜单图标" v-model="item.icon" @change="onUpdateItem(index)"></input-normal>
            <input-normal class="margin-top-10" label="按钮名" v-model="item.title" @change="onUpdateItem(index)"></input-normal>
          </div>
          <dropdown-normal label="操作类型" :valLists="MENU_PATTERN" v-model="item.eventType" @change="onChangeDropdown(index)"></dropdown-normal>
          <component
            v-if="getCompType(item.eventType) == 'DropdownNormal'"
            class="margin-top-10"
            :is="getCompType(item.eventType)"
            :label="getLabel(item.eventType)"
            v-model="item.value"
            :valLists="getLists(item.eventType)"
            @change="onUpdateItem(index)"
          ></component>
          <component
            v-else
            class="margin-top-10"
            :is="getCompType(item.eventType)"
            :placeholder="getPlaceholder(item.eventType)"
            :label="getLabel(item.eventType)"
            v-model="item.value"
            @change="onUpdateItem(index)"
          ></component>
        </el-collapse-item>
      </el-collapse>
    </el-form>
  </right-template>
</template>

<script>
  import RightTemplate from '@/views/child/right/right-template.vue'
  import TextareaNormal from '@/views/components/edit/TextareaNormal.vue'
  import SliderNormal from '@/views/components/edit/SliderNormal.vue'
  import ColorNormal from '@/views/components/edit/ColorNormal.vue'
  import InputNormal from '@/views/components/edit/InputNormal.vue'
  import DropdownNormal from '@/views/components/edit/DropdownNormal.vue'
  import AddImgCon from '@/views/components/add-img-con.vue'
  import SwitchNormal from '@/views/components/edit/SwitchNormal.vue'

  import {  mapGetters } from 'vuex'
  import { MENU_PATTERN } from '@/common/events';
  import { getMenuItemByEventType } from '@/common/events';
  import { editUtils } from '@/views/js/edit-utils'

  export default {
    name: "RightMenu",
    mixins: [editUtils],
    setup () {
      return {
        MENU_PATTERN: MENU_PATTERN,
      }
    },
    components: {
      RightTemplate,
      ColorNormal,
      SliderNormal,
      AddImgCon,
      InputNormal,
      DropdownNormal,
      SwitchNormal,
      TextareaNormal
    },
    computed: {
      ...mapGetters("components", {
        pages: "getH5Pages",
        pops: "getPopPages"
      }),
    },
    methods:{
      getLists(eventType) {
        let list = [];
        if (eventType == "layer") {
          this.pushPops(list)
        } else if (eventType == "anchor") {
          this.pushPages(list)
        }
        return list;
      },
      onChangeDropdown(index){
        this.lists[index].value = '';
        this.onUpdateItem(index)
      },
      getPlaceholder(eventType){
        let item = getMenuItemByEventType(eventType)
        return item.placeholder;
      },
      getLabel(eventType){
        let item = getMenuItemByEventType(eventType)
        return item.label;
      },
      getCompType(eventType){
        let item = getMenuItemByEventType(eventType)
        return item.compType;
      },
      onUpdateItem(index){
        let params = {item: this.lists[index], index};
        this.updateComponentItem(params);
      },
    },
  }
</script>
